var input = document.querySelectorAll('input');
var btn = document.querySelector('.btn');
var signId = location.search.split('=')[1];
var xhr = new XMLHttpRequest();
xhr.open('get', 'http://192.168.20.50:3008/api/student/getStudent?id=' + signId);
xhr.send();
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        var data = JSON.parse(xhr.responseText);
        data.forEach(function(value) {
            input[0].value = value.clazz;
            input[1].value = value.name;
            input[2].value = value.gender;
            input[3].value = value.age;
            input[4].value = value.hobby;
            input[5].value = value.remark;
            input[6].value = value.address;
            input[7].value = value.tel;
            input[8].value = value.date;
        })
    }
}

btn.onclick = function() {
    var obj = {
        id: signId,
        clazz: input[0].value,
        name: input[1].value,
        gender: input[2].value,
        age: input[3].value,
        hobby: input[4].value,
        remark: input[5].value,
        address: input[6].value,
        tel: input[7].value,
        date: input[8].value
    }
    var xhr2 = new XMLHttpRequest();
    xhr2.open('post', 'http://192.168.20.50:3008/api/student/updateStudent');
    xhr2.setRequestHeader('Content-type', 'application/json');
    xhr2.send(JSON.stringify(obj));
    xhr2.onreadystatechange = function() {
        if (xhr2.readyState == 4) {
            console.log(xhr2.responseText);
        }
    }
}